package club.hicode.daydayup.threadlocal.demo2;

/**
 * 窗口程序
 *
 * @author Liu Chunfu
 * @date 2018-08-09 下午8:41
 **/
public class TickWindwoRunable implements Runnable {

    private int index = 1;

    private final static int MAX = 100;

    private static Object MUTEX = new Object();

    @Override
    public void run() {
        synchronized (MUTEX) {
            while (index < MAX) {
                //synchronized (MUTEX) {
                System.out.println(Thread.currentThread() + " 的号码是：" + (index++));
            }
        }
    }

    public static void main(String[] args) {
        final TickWindwoRunable task = new TickWindwoRunable();

        Thread win1 = new Thread(task, "一号窗口");
        Thread win2 = new Thread(task, "二号窗口");
        Thread win3 = new Thread(task, "三号窗口");
        Thread win4 = new Thread(task, "四号窗口");

        win1.start();
        win2.start();
        win3.start();
        win4.start();

    }
}
